<?php
# @Author: yongleicheng <jetox>
# @Date:   2017-11-21T02:58:02+08:00
# @Email:  admin@weiqisheng.cn
# @Project: WQSCMS
# @Filename: Common.php
# @Last modified by:   jetox
# @Last modified time: 2017-11-21T07:28:17+08:00
# @Copyright: 微企胜网络科技有限公司




namespace app\admin\controller;

use think\Request;
use think\Db;
use think\Controller;

class Common extends Controller
{
    protected $mod;
    protected $role;
    protected $system;
    protected $nav;
    protected $menudata;
    protected $cache_model;
    protected $categorys;
    protected $module;
    protected $moduleid;
    protected $adminRules;
    protected $HrefId;
    public function _initialize()
    {

        //判断管理员是否登录
        if (!session('aid')) {
            $this->redirect('login/index');
        }
        define('MODULE_NAME', strtolower(request()->controller()));
        define('ACTION_NAME', strtolower(request()->action()));
        //权限管理
        //当前操作权限ID
        if (session('aid')!=1) {
            $this->HrefId = db('auth_rule')->where('href', MODULE_NAME.'/'.ACTION_NAME)->value('id');
            //当前管理员权限
            $map['a.admin_id'] = session('aid');
            $rules=Db::table(config('database.prefix').'admin')->alias('a')
                ->join(config('database.prefix').'auth_group ag', 'a.group_id = ag.group_id', 'left')
                ->where($map)
                ->value('ag.rules');
            $this->adminRules = explode(',', $rules);
            if ($this->HrefId) {
                if (!in_array($this->HrefId, $this->adminRules)) {
                    $this->error('您无此操作权限', 'index');
                }
            }
        }
        $this->system = F('System');
        $this->categorys = F('Category');
        $this->module = F('Module');
        $this->mod = F('Mod');
        $this->role = F('Role');
        $this->cache_model=array('Module','Role','Category','Posid','Field','System');
        if (empty($this->system)) {
            foreach ($this->cache_model as $r) {
                savecache($r);
            }
        }
    }
    //空操作
    public function _empty()
    {
        return $this->error('空操作，返回上次访问页面中...');
    }
}
